<?php
class QuestionService extends My_Service
{   
	public function buildQueryData($orderBy = "", $orderDirection="",
	$key = "", $field = "", $params = null)
	{
		if(empty($orderBy))
		{
			$orderBy = "ordering";
		}
		return parent::buildQueryData($orderBy,$orderDirection,$key,$field,$params);
	}
	
    public function check()
    {
		//validate ask
		$titleVald = new Zend_Validate_StringLength(10);
		if(!$titleVald->isValid($_POST['ask']))
		{
			$this->_errorList["ask"] = My_Message::get("S003|Ask|10");
			return false;
		}
				
		if(empty($this->_errorList) == false)
		{
			return false;
		}
		return true;
    }
    
	public function bind()
	{
		$question = new QuestionDTO( );
		if(!empty($_POST['questionId']))//case edit
		{
			$question = $this->load($_POST['questionId']);
		}
		else//case insert
		{
			$question->ordering = 1;
		}
		$question->ask = $_POST['ask'];
		$question->answer = $_POST['answer'];
		$question->status = $_POST['status'];
		
		return $question;
	}
    
    public function store()
    {
    	//check input data
    	if(!$this->check())
    	{
			return false;
    	}
    	
    	//bind data
    	$question = $this->bind();
    	
    	//save data
    	$this->save($question);
    	return true;
    }
    
    public function getPublish()
    {
    	return $this->getDAO()->getPublish();
    }
    
}
?>